package com.pig4cloud.pigx.wxApi.util;

import org.apache.commons.lang3.StringUtils;

import java.util.Objects;
import java.util.regex.Pattern;

/**
 * @program: lawyer
 * @description: 验证工具类
 * @author: Mr.An
 * @create: 2020-12-29 23:21
 **/
public class VerifyUtil {

    private static final Pattern emailRE = Pattern.compile("^[A-Za-z0-9._%+-]+@(?:[A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}$");
    private static final Pattern phonePattern = Pattern.compile("^1(3|5|7|8|4)\\d{9}");

    /**
     * 是否手机号
     * @param s
     * @return
     */
    public static boolean isPhone(String s) {
        if (StringUtils.isBlank(s)) {
            return false;
        }
        return phonePattern.matcher(Objects.requireNonNull(s)).matches();
    }

    /**
     * 是否邮箱
     * @param email
     * @return
     */
    public static boolean isEmail(String email) {
        if (StringUtils.isBlank(email)) {
            return false;
        }
        if (email.length() < 3 || email.length() > 50) {
            return false;
        }

        if (!emailRE.matcher(email).matches()) {
            return false;
        }
        return true;
    }
}
